<template>
  <el-card>
    <template #header>
      <div>throttleWait【useRequest】</div>
    </template>
    <div>
      <div style="margin-top: 16px">
        <el-input type="text" v-model="text" />
      </div>
      <div style="margin-top: 16px">
        value：{{ data?.data?.result?.userInfo?.username }}
      </div>
    </div>
  </el-card>
</template>

<script setup>
  import { useRequest, useTimeout } from "vue-hooks-plus";

  const text = ref("");

  const throttleWait = ref(500);

  useTimeout(() => {
    throttleWait.value = 3000;
  }, 2000);

  function getUsername() {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(`${String(Date.now())}`);
      }, 1000);
    });
  }

  const { data, run } = useRequest(() => getUsername(), {
    throttleWait,
    manual: true,
  });

  watch(text, async (c) => {
    await run();
  });
</script>

<style lang="scss" scoped></style>
